import React, { useState } from 'react';
import {random as r} from 'lodash';

export default function ChangeBg() {
  //声明状态
  let [bg, setBg] = useState('rgb(0,0,0)');
  //声明函数
  let changeBackground = () => {
    setBg(`rgb(${r(100, 200)},${r(100, 200)},${r(100, 200)})`);
  }
  return (
    <div 
      style={{width: 400, height: 300, background: bg, margin: '50px auto'}}
      onClick={changeBackground}
    ></div>
  )
}
